package ru.amse.vlassiev.TestPackage;

import ru.amse.vlassiev.model.*;
import ru.amse.vlassiev.reader.IReader;
import ru.amse.vlassiev.reader.LogFileReader;
import ru.amse.vlassiev.view.*;
import junit.framework.TestCase;

import java.io.File;
import java.util.*;

public class FilterTest extends TestCase {

	private TestView myView;
	
	public FilterTest(String name) {
		super(name);
	}
	
	private class TestView implements IView {
		
		private List<String> myCapture = new ArrayList<String>();
		private List<Long> myValue = new ArrayList<Long>();
		
		public void update(String capture, long value) {
			myCapture.add(capture);
			myValue.add(value);
		}
		
		public String getCapture(int n) {
			return myCapture.get(n); 
		}

		public long getValue(int n) {
			return myValue.get(n); 
		}

	}
	
	public void setUp() {
		try {
			myView = new TestView();
			IFilter filter = new Filter("", 1, myView);
			IFiltrator filtrator = new Filtrator();
			filtrator.addFilter(filter);
			IReader reader = new LogFileReader(new File("test"), 100);
			reader.addListener(filtrator);
			reader.start();
		} catch (Exception e) {
			fail("Input is good, but exception is thrown.");
		}
	}
	
	public void testValueTrue() {
		try { Thread.sleep(1500); } catch (Exception e) {}
		assertEquals(26 * 8 * 6, myView.getValue(0));
	}

	public void testValueFalse() {
		try { Thread.sleep(1500); } catch (Exception e) {}
			assertNotSame(0, myView.getValue(0));
	}

}
